set scheme s1color

clear all

use "../pseudo_data/holdings.dta", clear

********************************************************************************
* * GENERATE VARIABLES
********************************************************************************

{

	* drop if no advisor id (code_conseiller)
	drop if (profile == "Highly Advised" | profile == "Lightly Advised") & missing(code_conseiller)

	encode profile, gen(profile_c)
	label define profile_lab 1 "Highly Advised" 2 "Lightly Advised" 3 "Not Advised"
	label values profile_c profile_lab


	* gen year
	gen year = year(daily_date)

	* gen week date
	gen weekly_date = wofd(daily_date)
	format weekly_date %tw

	* gen quarterly date
	gen quarterly_date = qofd(daily_date)
	format quarterly_date %tq

	* gen semester date
	cap drop semester*
	gen semester = halfyear(daily_date)
	gen semester_date = yh(year, semester)
	format semester_date %th


	* min date as advisee
	bysort numero_compte: egen min_date_investor= min(daily_date)
	bysort numero_compte: egen max_date_investor= max(daily_date)

	* define cohort variable 
	bysort numero_compte: egen cohort_semester= min(semester_date)

	* check total wealth 
	gen valorisation = quantite*prccd
	bysort numero_compte daily_date: egen total_asset = sum(valorisation)
	gen weight = valorisation/total_asset
	gen weight100 = weight*100
	bysort numero_compte: egen total_asset_med = median(total_asset)

	* hhi 
	bysort numero_compte daily_date: egen hhi_portfolio = sum((weight)^2)


	* weighted average of mkt cap in the portfolio 
	bysort numero_compte daily_date: egen port_weight_mkt_cap = sum(weight*mkt_cap)

	* weighted average of beta in the portfolio 
	bysort numero_compte daily_date: egen port_weight_beta_mkt_rf = sum(weight*beta_mkt_rf)
	bysort numero_compte daily_date: egen port_weight_beta_smb = sum(weight*beta_smb)
	bysort numero_compte daily_date: egen port_weight_beta_hml = sum(weight*beta_hml)
	bysort numero_compte daily_date: egen port_weight_beta_mom = sum(weight*beta_mom)


	* drop extreme total assets
	drop if total_asset==0
	drop if total_asset>10^9

	* tag individual, i.e., account number (numero_compte)
	egen tag_individual = tag(numero_compte)


	* number of trade by year 
	gen trade_dummy = (quantite_transaction!=0)	
	bysort year numero_compte: egen nb_trade_year = sum(trade_dummy)
	egen tag_individual_year = tag(numero_compte year)
	bysort numero_compte: egen nb_trade_year_med = median(nb_trade_year/(tag_individual_year==1))


	* portfolio concentration
	encode code_valeur, gen(asset_id)
	bysort numero_compte daily_date: egen n_asset = nvals(asset_id)
	gen log_n_asset = log(n_asset)
	label variable log_n_asset "Log(Nb. Stocks)"
	bysort numero_compte: egen n_asset_med = median(n_asset)


	* Sell and Buy dummies
	gen sell_dummy = 0
	replace sell_dummy = 1 if quantite_transaction<0

	gen buy_dummy = 0
	replace buy_dummy = 1 if quantite_transaction>0


	* Distribution of holding period
	bysort numero_compte code_valeur: gen n_obs_compte_valeur = _n
	bysort numero_compte: egen holding_period_med = median(n_obs_compte_valeur)


	* before first sale
	bysort numero_compte code_valeur: egen first_sale_compte_valeur = min(daily_date/(sell_dummy>0))
	bysort numero_compte code_valeur: gen n_obs_compte_valeur_bef_sale = _n if ((daily_date<=first_sale_compte_valeur & !missing(first_sale_compte_valeur)) | missing(first_sale_compte_valeur))
	bysort numero_compte: egen holding_period_bef_sale_med = median(n_obs_compte_valeur_bef_sale)


	* Sell and Buy quantities
	gen arcsinh_buy_quantity = 0
	replace arcsinh_buy_quantity = ln(quantite_transaction + sqrt(quantite_transaction^2 + 1)) if buy_dummy>0

	gen arcsinh_sell_quantity = 0
	replace arcsinh_sell_quantity = ln(-quantite_transaction + sqrt((-quantite_transaction)^2 + 1)) if sell_dummy>0

	* Sell and Buy amounts
	gen buy_amount = 0
	replace buy_amount = quantite_transaction*prccd if buy_dummy>0

	gen sell_amount = 0
	replace sell_amount = -quantite_transaction*prccd if sell_dummy>0

	gen arcsinh_buy_amount = 0
	replace arcsinh_buy_amount = ln(buy_amount + sqrt(buy_amount^2 + 1))

	gen arcsinh_sell_amount = 0
	replace arcsinh_sell_amount = ln(sell_amount + sqrt(sell_amount^2 + 1))

	* Turnover
	bysort numero_compte daily_date: egen sell_amount_day = sum(sell_amount)
	bysort numero_compte daily_date: egen buy_amount_day = sum(buy_amount)
	egen min_trade_amount_day = rowmin(sell_amount_day buy_amount_day)

	egen tag_individual_day = tag(numero_compte daily_date)
	bysort numero_compte year: egen min_trade_amount_year = sum(min_trade_amount_day / (tag_individual_day==1))
	bysort numero_compte year: egen total_asset_mean_year = mean(total_asset)
	gen turnover_ratio = min_trade_amount_day/total_asset if tag_individual_day==1
	gen turnover_ratio_year = min_trade_amount_year/total_asset_mean_year if tag_individual_year==1

	bysort numero_compte: egen turnover_ratio_med = median(turnover_ratio / (tag_individual_day==1))
	bysort numero_compte: egen turnover_ratio_year_med = median(turnover_ratio_year / (tag_individual_year==1))

	* store min/max date in sample
	quiet sum daily_date
	scalar max_date_in_sample = r(max)
	scalar min_date_in_sample = r(min)

	* flag exit of clients
	gen exit_client = (max_date_investor < max_date_in_sample)

	* create advisor id
	encode code_conseiller, gen(advisor_id)

	* to multiply coeff by 100
	gen sell_dummy100 = sell_dummy*100
	gen buy_dummy100 = buy_dummy*100

	* tag month 
	egen tag_month = tag(monthly_date)

	* flag exit in the month 
	gen max_month_investor = mofd(max_date_investor)
	gen exit_client_month = (monthly_date==max_month_investor) & exit_client==1


	* treated and control 
	gen treated = 1 if profile=="Highly Advised"
	replace treated = 0 if missing(treated)

	* store first date for each account-asset
	sort numero_compte code_valeur daily_date, stable
	by numero_compte code_valeur : egen first_date_compte_valeur = min(daily_date)

	* compute daily return
	cap drop return
	sort numero_compte asset_id daily_date
	by numero_compte asset_id: gen return = (prccd - prccd[_n-1])/prccd[_n-1]

	gen gain_euro = quantite*(prccd - pam)
	by numero_compte asset_id: gen gain_euro_asof_t_1 = gain_euro[_n-1]

	bysort numero_compte daily_date: egen portfolio_gain_euro_t_1 = sum(gain_euro_asof_t_1)
	gen portfolio_gain_dummy = (portfolio_gain_euro_t_1>0) if !missing(portfolio_gain_euro_t_1)

	* compute (paper) asset return since purchase 
	drop if pam==0 // pam = prix achat moyen (average purchasing price)
	gen return_asof_t = (prccd/pam) - 1
	sort numero_compte asset_id daily_date, stable
	by numero_compte asset_id: gen return_asof_t_1 = return_asof_t[_n-1]


	* clean returns
	foreach var of varlist return return_asof_t return_asof_t_1 ret_stock_month ret_next alpha_4f{
		quiet sum `var', d
		local lower = (r(p50) - 5*(r(p75) - r(p25)))
		local upper = (r(p50)+5*(r(p75) - r(p25)))
		disp `lower'
		disp `upper'
		replace `var' =  `lower' if `var'< `lower' & !missing(`var')
		replace `var' = `upper' if `var'> `upper' & !missing(`var')
		sum `var', d
	}


	* compute daily portfolio return 
	sort numero_compte daily_date
	by numero_compte daily_date: egen ret_next_day = sum(weight*ret_next)	

	sort tag_individual_day numero_compte daily_date 
	by tag_individual_day numero_compte: gen ret_today = ret_next_day[_n-1] if tag_individual_day==1

	cap drop tmp 
	bysort numero_compte daily_date: egen tmp = mean(ret_today)
	replace ret_today = tmp 
	replace ret_today = 0 if missing(ret_today)

	cap drop tmp
	bysort numero_compte daily_date: egen tmp = sum(alpha_4f*weight)
	replace alpha_4f = tmp 
	drop tmp
	replace alpha_4f = 0 if missing(alpha_4f)


	* define expected return 
	gen exp_ret_4f = ret_today - alpha_4f

	* compound over month
	cap drop tag_individual_month
	sort numero_compte monthly_date daily_date
	by numero_compte monthly_date: gen tag_individual_month = (_n==_N)

	foreach var of varlist ret_today alpha_4f exp_ret_4f{
		cap drop tmp
		gen tmp = (1+`var') if tag_individual_day==1
		cap drop prod_tmp

		sort tag_individual_day numero_compte monthly_date daily_date
		by tag_individual_day numero_compte monthly_date: gen prod_tmp = tmp[1] if tag_individual_day==1 & !missing(tmp[1])
		by tag_individual_day numero_compte monthly_date: replace prod_tmp = prod_tmp[_n-1]*tmp if _n>1 & tag_individual_day==1 & !missing(tmp)
		by tag_individual_day numero_compte monthly_date: replace prod_tmp = prod_tmp[_N] if tag_individual_day==1 & !missing(tmp[_N])
		cap drop `var'_thismonth
		gen `var'_thismonth = prod_tmp - 1
		cap drop tmp 
		bysort numero_compte monthly_date: egen tmp = mean(`var'_thismonth)
		replace `var'_thismonth = tmp 
		drop tmp
	}

	rename ret_today_thismonth ret_thismonth


	* compute difference between compounded return and compounded expected return
	gen alphabh_4f_thismonth = ret_thismonth - exp_ret_4f_thismonth

	gen ret_thismonth_perc = ret_thismonth*100
	gen alphabh_4f_thismonth_perc = alphabh_4f_thismonth*100


	gen return_pos_t_1 = return_asof_t_1 if return_asof_t_1>0
	replace return_pos_t_1 = 0 if missing(return_pos_t_1)

	gen return_neg_t_1 = return_asof_t_1 if return_asof_t_1<0
	replace return_neg_t_1 = 0 if missing(return_neg_t_1)

	gen volatility_pos_t_1 = rol_vol if return_asof_t_1>0
	replace volatility_pos_t_1 = 0 if missing(volatility_pos_t_1)

	gen volatility_neg_t_1 = rol_vol if return_asof_t_1<0
	replace volatility_neg_t_1 = 0 if missing(volatility_neg_t_1)

	* gen dummy for gain 
	gen gain_dummy = (return_asof_t_1 > 0) if !missing(return_asof_t_1)

	* post period 
	scalar plateform_intro_date = mdy(1,15,2018)
	gen post_platform = daily_date > plateform_intro_date

	* gen interactions 
	gen gain_x_post = gain_dummy*post_platform

	* gen log price
	gen log_pam = log(pam)

	* compute time since purchasing date
	sort numero_compte code_valeur daily_date, stable
	by numero_compte code_valeur: egen min_date_compte_valeur = min(daily_date)
	gen day_since_purchase = n_obs_compte_valeur
	gen log_day_since_purchase = log(day_since_purchase)
	gen sqrt_day_since_purchase = sqrt(day_since_purchase)

	* gen interactions 
	gen ret_pos_x_sqrt_day_sin_purchase = return_pos_t_1*sqrt_day_since_purchase
	gen ret_neg_x_sqrt_day_sin_purchase = return_neg_t_1*sqrt_day_since_purchase
	gen gain_x_sqrt_day_sin_purchase = gain_dummy*sqrt_day_since_purchase


	* follow-on returns 
	egen tag_asset_day = tag(asset_id daily_date)
	sort tag_asset_day asset_id daily_date
	by tag_asset_day asset_id: gen next_1m_ret = 100*(prccd[_n+21]/prccd - 1) if tag_asset_day==1
	by tag_asset_day asset_id: gen next_1q_ret = 100*(prccd[_n+63]/prccd - 1) if tag_asset_day==1
	by tag_asset_day asset_id: gen next_1s_ret = 100*(prccd[_n+126]/prccd - 1) if tag_asset_day==1
	by tag_asset_day asset_id: gen next_1y_ret = 100*(prccd[_n+252]/prccd - 1) if tag_asset_day==1
	by tag_asset_day asset_id: gen next_2y_ret = 100*(prccd[_n+504]/prccd - 1) if tag_asset_day==1
	by tag_asset_day asset_id: gen next_3y_ret = 100*(prccd[_n+756]/prccd - 1) if tag_asset_day==1

	bysort asset_id daily_date: egen next_1m_retmean = mean(next_1m_ret)
	bysort asset_id daily_date: egen next_1q_retmean = mean(next_1q_ret)
	bysort asset_id daily_date: egen next_1s_retmean = mean(next_1s_ret)
	bysort asset_id daily_date: egen next_1y_retmean = mean(next_1y_ret)
	bysort asset_id daily_date: egen next_2y_retmean = mean(next_2y_ret)
	bysort asset_id daily_date: egen next_3y_retmean = mean(next_3y_ret)

	replace next_1m_ret = next_1m_retmean
	replace next_1q_ret = next_1q_retmean
	replace next_1s_ret = next_1s_retmean
	replace next_1y_ret = next_1y_retmean
	replace next_2y_ret = next_2y_retmean
	replace next_3y_ret = next_3y_retmean

	drop next_1m_retmean
	drop next_1q_retmean
	drop next_1s_retmean
	drop next_1y_retmean
	drop next_2y_retmean
	drop next_3y_retmean


	* advisory committee reco
	gen buy_signal_committee = 0
	replace buy_signal_committee = 1 if signal_comite == "buy"

	gen sell_signal_committee = 0
	replace sell_signal_committee = 1 if signal_comite == "sell"

	label variable sell_signal_committee "Sell Reco"
	label variable buy_signal_committee "Buy Reco"

	label define sell_signal_lab 0 "" 1 "Sell Reco"
	label values sell_signal_committee sell_signal_lab

	label define buy_signal_lab 0 "" 1 "Buy Reco"
	label values buy_signal_committee buy_signal_lab

	sort numero_compte asset_id daily_date
	by numero_compte asset_id: gen bought_w_reco = (buy_dummy*buy_signal_committee) if _n==1
	by numero_compte asset_id: replace bought_w_reco = bought_w_reco[_n-1]*(buy_dummy==0)  + buy_signal_committee*(buy_dummy==1) if _n>1 
	label variable bought_w_reco "Purchased Following Recommendation"

	label define bought_w_reco_lab 1 "Purchased Following Recommendation" 0 ""
	label values bought_w_reco bought_w_reco_lab


	* flag sell/buy in the past days 
	sort numero_compte asset_id daily_date

	by numero_compte asset_id: gen buy_lastweek = buy_dummy[_n-1] + buy_dummy[_n-2] + buy_dummy[_n-3] + buy_dummy[_n-4] + buy_dummy[_n-5]   
	by numero_compte asset_id: replace buy_lastweek = buy_dummy[_n-1] + buy_dummy[_n-2] + buy_dummy[_n-3] + buy_dummy[_n-4] if missing(buy_lastweek)
	by numero_compte asset_id: replace buy_lastweek = buy_dummy[_n-1] + buy_dummy[_n-2] + buy_dummy[_n-3] if missing(buy_lastweek)
	by numero_compte asset_id: replace buy_lastweek = buy_dummy[_n-1] + buy_dummy[_n-2] if missing(buy_lastweek)
	by numero_compte asset_id: replace buy_lastweek = buy_dummy[_n-1] if missing(buy_lastweek)
	replace buy_lastweek =0 if missing(buy_lastweek)
	replace buy_lastweek =1 if buy_lastweek>1
	gen buy_lastweek100 =100*buy_lastweek

	by numero_compte asset_id: gen sell_lastweek = sell_dummy[_n-1] + sell_dummy[_n-2] + sell_dummy[_n-3] + sell_dummy[_n-4] + sell_dummy[_n-5]   
	by numero_compte asset_id: replace sell_lastweek = sell_dummy[_n-1] + sell_dummy[_n-2] + sell_dummy[_n-3] + sell_dummy[_n-4] if missing(sell_lastweek)
	by numero_compte asset_id: replace sell_lastweek = sell_dummy[_n-1] + sell_dummy[_n-2] + sell_dummy[_n-3] if missing(sell_lastweek)
	by numero_compte asset_id: replace sell_lastweek = sell_dummy[_n-1] + sell_dummy[_n-2] if missing(sell_lastweek)
	by numero_compte asset_id: replace sell_lastweek = sell_dummy[_n-1] if missing(sell_lastweek)
	replace sell_lastweek =0 if missing(sell_lastweek)
	replace sell_lastweek =1 if sell_lastweek>1
	gen sell_lastweek100 =100*sell_lastweek

	* determine whether already in portfolio 
	by numero_compte asset_id: gen in_portfolio = quantite[_n-1]>0 if !missing(quantite[_n-1])
	replace in_portfolio = 0 if missing(in_portfolio)
	replace in_portfolio = 1 if sell_dummy==1

	gen in_portfolio100 = 100*in_portfolio

	* compute average monthly return by client (weighted average of return in the portfolio)

	bysort numero_compte daily_date: egen ret_month = sum(weight*ret_stock_month)
	replace ret_month = 100*ret_month

	bysort numero_compte: egen ret_month_avg = mean(ret_thismonth / (tag_individual_month==1))
	bysort numero_compte: egen alpha_4f_month_avg = mean(alpha_4f_thismonth / (tag_individual_month==1))

	bysort numero_compte: egen alphabh_4f_month_avg = mean(alphabh_4f_thismonth / (tag_individual_month==1))


	* return 

	cap drop ret_l*month
	cap drop alpha_l*month
	cap drop alpha_4f_l*month
	forvalues i=1/12{
		* raw return
		sort tag_individual_month numero_compte monthly_date
		by tag_individual_month numero_compte: gen ret_l`i'month = ret_thismonth[_n-`i'] if tag_individual_month==1

		cap drop tmp
		bysort numero_compte monthly_date: egen tmp = mean(ret_l`i'month)
		replace ret_l`i'month = tmp
		drop tmp

		* alpha 4f

		sort tag_individual_month numero_compte monthly_date
		by tag_individual_month numero_compte: gen alpha_4f_l`i'month = alpha_4f_thismonth[_n-`i'] if tag_individual_month==1

		cap drop tmp
		bysort numero_compte monthly_date: egen tmp = mean(alpha_4f_l`i'month)
		replace alpha_4f_l`i'month = tmp
		drop tmp

	}



	* hhi 
	bysort numero_compte monthly_date: egen hhi_portfolio_month = mean(hhi_portfolio/(tag_individual_month==1))


	* label variables
	label variable log_pam "Log(Buy Price)"
	label variable sqrt_day_since_purchase " $ \sqrt{ \text{Time Owned}} $ "
	label variable gain_x_sqrt_day_sin_purchase "Gain $ \times \sqrt{ \text{Time Owned}} $ "
	label variable return_pos_t_1 "Return(+)"
	label variable return_neg_t_1 "Return(-)"
	label variable volatility_pos_t_1 "Volatility(+)"
	label variable volatility_neg_t_1 "Volatility(-)"
	label variable ret_pos_x_sqrt_day_sin_purchase "Return(+) $ \times \sqrt{ \text{Time Owned}} $"
	label variable ret_neg_x_sqrt_day_sin_purchase "Return(-) $ \times \sqrt{ \text{Time Owned}} $"

	label variable gain_dummy "Gain"
	cap label drop gain_lab
	label define gain_lab 0 "" 1 "Gain"
	label values gain_dummy gain_lab

	label variable portfolio_gain_dummy "Portfolio Gain"
	cap label drop port_gain_lab
	label define port_gain_lab 0 "" 1 "Portfolio Gain"
	label values portfolio_gain_dummy port_gain_lab

	label variable in_portfolio100 "Already in Portfolio $ \times $ 100"
	label variable sell_lastweek100 "Sold Last Week $ \times $ 100"
	label variable buy_lastweek100 "Bought Last Week $ \times $ 100"

	label variable in_portfolio "Already in Portfolio"
	label variable sell_lastweek "Sold Last Week"
	label variable buy_lastweek "Bought Last Week"

}



********************************************************************************
* TABLE 1
********************************************************************************


{

	* flag advisor-profile 
	bysort advisor_id profile: gen tag_advisor_profile=(_n==_N)

	* temp variables
	gen individual_type_tmp = tag_individual if tag_individual==1
	gen advisor_type_tmp = tag_advisor_profile if tag_advisor_profile==1

	* percentage return and alpha
	gen ret_month_avg_perc = ret_month_avg*100
	gen alphabh_4f_month_avg_perc = alphabh_4f_month_avg*100




	* list of variables to summarize
	global var_inv = "total_asset_med n_asset_med nb_trade_year_med holding_period_med holding_period_bef_sale_med ret_month_avg_perc alphabh_4f_month_avg_perc"

	label var total_asset_med "Total Assets (EUR)"
	label var n_asset_med "Number of Stocks"
	label var nb_trade_year_med "Number of Trades per Year"
	label var holding_period_med "Holding Period (Days)"
	label var holding_period_bef_sale_med "Holding Period Before 1st Sale (Days)"
	label var ret_month_avg_perc "Monthly Return (\%)"
	label var alphabh_4f_month_avg_perc "Monthly Risk-Adjusted Return (\%)"

	global list $var_inv 
	local nvar : word count $list
	local nvar = `nvar'+2

	* loop over profiles 
	foreach l in "Highly Advised" "Lightly Advised" "Not Advised"{

		disp "`l'"
		matrix define m=J(`nvar',8,.)

		* count investors
		local var_name_1 = "Number of Investors"

		tabstat individual_type_tmp if profile=="`l'", ///
			columns(variables) ///
			stat(n mean sd p5 p25  p50  p75 p95 ) /// 
			save

		return list
		matrix stats=r(StatTotal)	

		matrix m[1,1]= stats[1,1]

		* count advisors 
		if "`l'"=="Highly Advised" |  "`l'"=="Lightly Advised"{
			local var_name_2 = "Number of Advisors"

			tabstat advisor_type_tmp if profile=="`l'", ///
				columns(variables) ///
				stat(n mean sd p5 p25  p50  p75 p95 ) /// 
				save


			return list
			matrix stats=r(StatTotal)	

			matrix m[2,1]= stats[1,1]
		}
		else{
			matrix m[2,1]= 0
		}

		local count = 2

		* summarize variables
		foreach variable in $var_inv{
			local count = `count'+1

			local var_name_tmp : variable label `variable'
			local var_name_`count' = subinstr("`var_name_tmp'", "_", "\_", .)


			tabstat `variable' if profile=="`l'" & tag_individual==1, ///
				columns(variables) ///
				stat(n mean sd p5 p25  p50  p75 p95 ) /// 
				save


			return list
			matrix stats=r(StatTotal)	


			matrix m[`count',2]= round(stats[2,1],.01)
			matrix m[`count',3]= round(stats[3,1],.01)
			matrix m[`count',4]= round(stats[4,1],.01)
			matrix m[`count',5]= round(stats[5,1],.01)
			matrix m[`count',6]= round(stats[6,1],.01)

			matrix m[`count',7]= round(stats[7,1],.01)
			matrix m[`count',8]= round(stats[8,1],.01)

		}


	}


	drop individual_type_tmp
	drop advisor_type_tmp
}


********************************************************************************
* TABLE 2
********************************************************************************

{

	eststo clear
	estimates clear


	reghdfe sell_dummy100 sell_signal_committee##b2.profile_c ///
		buy_signal_committee##b2.profile_c ///
		if profile!="Not Advised", absorb(numero_compte asset_id daily_date) cluster(numero_compte daily_date) noconstant

	estimates store follow_sell_1



	reghdfe sell_dummy100 sell_signal_committee##b2.profile_c ///
		buy_signal_committee##b2.profile_c ///
		if profile!="Not Advised", absorb(numero_compte#daily_date asset_id) cluster(numero_compte daily_date) noconstant

	estimates store follow_sell_2



	reghdfe buy_dummy100 sell_signal_committee##b2.profile_c ///
		buy_signal_committee##b2.profile_c ///
		if profile!="Not Advised", absorb(numero_compte asset_id daily_date) cluster(numero_compte daily_date) noconstant

	estimates store follow_buy_1



	reghdfe buy_dummy100 sell_signal_committee##b2.profile_c ///
		buy_signal_committee##b2.profile_c ///
		if profile!="Not Advised", absorb(numero_compte#daily_date asset_id) cluster(numero_compte daily_date) noconstant

	estimates store follow_buy_2


}	


********************************************************************************
* FIGURES 3 AND 4 
********************************************************************************


{
	* week variables
	bysort numero_compte asset_id weekly_date: gen tag_individual_asset_week = (_n==_N)
	bysort numero_compte asset_id weekly_date: egen sell_dummy100_week = max(sell_dummy100)
	bysort asset_id weekly_date: gen tag_asset_week = (_n==_N)
	bysort numero_compte asset_id weekly_date: egen buy_dummy100_week = max(buy_dummy100)
	bysort asset_id weekly_date: egen sell_signal_committee_week = max(sell_signal_committee)
	bysort asset_id weekly_date: egen buy_signal_committee_week = max(buy_signal_committee)

	{

		* create pre/post week dummies
		{

			sort tag_asset_week asset_id weekly_date

			* sell post 
			gen sell_signal_week1=0
			by tag_asset_week asset_id: replace sell_signal_week1 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==0 & tag_asset_week==1	

			gen sell_signal_week2=0
			by tag_asset_week asset_id: replace sell_signal_week2 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==0 & tag_asset_week==1	

			gen sell_signal_week3=0
			by tag_asset_week asset_id: replace sell_signal_week3 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==1 & sell_signal_committee_week[_n-3]==0 & tag_asset_week==1	

			gen sell_signal_week4=0
			by tag_asset_week asset_id: replace sell_signal_week4 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==1 & sell_signal_committee_week[_n-3]==1 & sell_signal_committee_week[_n-4]==0 & tag_asset_week==1

			gen sell_signal_week5=0
			by tag_asset_week asset_id: replace sell_signal_week5 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==1 & sell_signal_committee_week[_n-3]==1 & sell_signal_committee_week[_n-4]==1 & sell_signal_committee_week[_n-5]==0 & tag_asset_week==1

			gen sell_signal_week6=0
			by tag_asset_week asset_id: replace sell_signal_week6 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==1 & sell_signal_committee_week[_n-3]==1 & sell_signal_committee_week[_n-4]==1 & sell_signal_committee_week[_n-5]==1 & sell_signal_committee_week[_n-6]==0 & tag_asset_week==1


			gen sell_signal_week7=0
			by tag_asset_week asset_id: replace sell_signal_week7 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==1 & sell_signal_committee_week[_n-3]==1 & sell_signal_committee_week[_n-4]==1 & sell_signal_committee_week[_n-5]==1 & sell_signal_committee_week[_n-6]==1 & sell_signal_committee_week[_n-7]==0 & tag_asset_week==1

			gen sell_signal_week8=0
			by tag_asset_week asset_id: replace sell_signal_week8 = 1 if sell_signal_committee_week==1 & sell_signal_committee_week[_n-1]==1 & sell_signal_committee_week[_n-2]==1 & sell_signal_committee_week[_n-3]==1 & sell_signal_committee_week[_n-4]==1 & sell_signal_committee_week[_n-5]==1 & sell_signal_committee_week[_n-6]==1 & sell_signal_committee_week[_n-7]==1 &  sell_signal_committee_week[_n-8]==0 & tag_asset_week==1


			* sell lead
			gen sell_signal_weekm1=0
			by tag_asset_week asset_id: replace sell_signal_weekm1 = 1 if sell_signal_committee_week==0 & sell_signal_committee_week[_n+1]==1 & tag_asset_week==1 

			gen sell_signal_weekm2=0
			by tag_asset_week asset_id: replace sell_signal_weekm2 = 1 if sell_signal_committee_week==0 & sell_signal_committee_week[_n+1]==0 & sell_signal_committee_week[_n+2]==1 & tag_asset_week==1	 

			gen sell_signal_weekm3=0
			by tag_asset_week asset_id: replace sell_signal_weekm3 = 1 if sell_signal_committee_week==0 & sell_signal_committee_week[_n+1]==0 & sell_signal_committee_week[_n+2]==0 & sell_signal_committee_week[_n+3]==1 & tag_asset_week==1 

			gen sell_signal_weekm4=0
			by tag_asset_week asset_id: replace sell_signal_weekm4 = 1 if sell_signal_committee_week==0 & sell_signal_committee_week[_n+1]==0 & sell_signal_committee_week[_n+2]==0 & sell_signal_committee_week[_n+3]==0 & sell_signal_committee_week[_n+4]==1 & tag_asset_week==1 



			* buy post
			gen buy_signal_week1=0
			by tag_asset_week asset_id: replace buy_signal_week1 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==0 & tag_asset_week==1	

			gen buy_signal_week2=0
			by tag_asset_week asset_id: replace buy_signal_week2 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==0 & tag_asset_week==1	

			gen buy_signal_week3=0
			by tag_asset_week asset_id: replace buy_signal_week3 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==1 & buy_signal_committee_week[_n-3]==0 & tag_asset_week==1	

			gen buy_signal_week4=0
			by tag_asset_week asset_id: replace buy_signal_week4 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==1 & buy_signal_committee_week[_n-3]==1 & buy_signal_committee_week[_n-4]==0 & tag_asset_week==1

			gen buy_signal_week5=0
			by tag_asset_week asset_id: replace buy_signal_week5 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==1 & buy_signal_committee_week[_n-3]==1 & buy_signal_committee_week[_n-4]==1 & buy_signal_committee_week[_n-5]==0 & tag_asset_week==1


			gen buy_signal_week6=0
			by tag_asset_week asset_id: replace buy_signal_week6 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==1 & buy_signal_committee_week[_n-3]==1 & buy_signal_committee_week[_n-4]==1 & buy_signal_committee_week[_n-5]==1 & buy_signal_committee_week[_n-6]==0 & tag_asset_week==1


			gen buy_signal_week7=0
			by tag_asset_week asset_id: replace buy_signal_week7 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==1 & buy_signal_committee_week[_n-3]==1 & buy_signal_committee_week[_n-4]==1 & buy_signal_committee_week[_n-5]==1 & buy_signal_committee_week[_n-6]==1 & buy_signal_committee_week[_n-7]==0 & tag_asset_week==1

			gen buy_signal_week8=0
			by tag_asset_week asset_id: replace buy_signal_week8 = 1 if buy_signal_committee_week==1 & buy_signal_committee_week[_n-1]==1 & buy_signal_committee_week[_n-2]==1 & buy_signal_committee_week[_n-3]==1 & buy_signal_committee_week[_n-4]==1 & buy_signal_committee_week[_n-5]==1 & buy_signal_committee_week[_n-6]==1 & buy_signal_committee_week[_n-7]==1 &  buy_signal_committee_week[_n-8]==0 & tag_asset_week==1


			* buy lead
			gen buy_signal_weekm1=0
			by tag_asset_week asset_id: replace buy_signal_weekm1 = 1 if buy_signal_committee_week==0 & buy_signal_committee_week[_n-1]==0 & buy_signal_committee_week[_n+1]==1 & tag_asset_week==1	

			gen buy_signal_weekm2=0
			by tag_asset_week asset_id: replace buy_signal_weekm2 = 1 if buy_signal_committee_week==0 & buy_signal_committee_week[_n-1]==0 & buy_signal_committee_week[_n+1]==0 & buy_signal_committee_week[_n+2]==1 & tag_asset_week==1	

			gen buy_signal_weekm3=0
			by tag_asset_week asset_id: replace buy_signal_weekm3 = 1 if buy_signal_committee_week==0 & buy_signal_committee_week[_n-1]==0 & buy_signal_committee_week[_n+1]==0 & buy_signal_committee_week[_n+2]==0 & buy_signal_committee_week[_n+3]==1 & tag_asset_week==1		

			gen buy_signal_weekm4=0
			by tag_asset_week asset_id: replace buy_signal_weekm4 = 1 if buy_signal_committee_week==0 & buy_signal_committee_week[_n-1]==0 & buy_signal_committee_week[_n+1]==0 & buy_signal_committee_week[_n+2]==0 & buy_signal_committee_week[_n+3]==0 & buy_signal_committee_week[_n+4]==1 & tag_asset_week==1		


			* fill and label 

			forvalues i=1/8{
				disp "`i'"
				cap bysort asset_id weekly_date: egen sell_signal_week_p`i' = max(sell_signal_week`i')
				cap bysort asset_id weekly_date: egen sell_signal_week_m`i' = max(sell_signal_weekm`i')

				cap bysort asset_id weekly_date: egen buy_signal_week_p`i' = max(buy_signal_week`i')
				cap bysort asset_id weekly_date: egen buy_signal_week_m`i' = max(buy_signal_weekm`i')

				cap bysort asset_id weekly_date: egen sell_signal_week_p`i'plus = max(sell_signal_week`i'plus)
				cap bysort asset_id weekly_date: egen sell_signal_week_m`i'plus = max(sell_signal_weekm`i'plus)

				cap bysort asset_id weekly_date: egen buy_signal_week_p`i'plus = max(buy_signal_week`i'plus)
				cap bysort asset_id weekly_date: egen buy_signal_week_m`i'plus = max(buy_signal_weekm`i'plus)

				cap label variable sell_signal_week_p`i' "`i'"
				cap label variable buy_signal_week_p`i' "`i'"

				cap label variable sell_signal_week_m`i' "-`i'"
				cap label variable buy_signal_week_m`i' "-`i'"

				cap label variable sell_signal_week_p`i'plus "`i'+"
				cap label variable buy_signal_week_p`i'plus "`i'+"

				cap label variable sell_signal_week_m`i'plus "-`i'+"
				cap label variable buy_signal_week_m`i'plus "-`i'+"


			}


		}



		* label values
		forvalues ww=1/8{
			cap label drop tmp_lab`ww'
			label define tmp_lab`ww' 0 "" 1 "Week `ww'"
			label values sell_signal_week_p`ww' tmp_lab`ww'
			label values buy_signal_week_p`ww' tmp_lab`ww'


		}

		forvalues ww=1/4{
			cap label drop tmp_labm`ww'
			label define tmp_labm`ww' 0 "" 1 "Week -`ww'"
			disp "Week -`ww'"
			label values sell_signal_week_m`ww' tmp_labm`ww'
			label values buy_signal_week_m`ww' tmp_labm`ww'

		}






		*** FIGURE 3 ****

		reghdfe sell_dummy100 ///
			sell_signal_week_m4##b2.profile_c ///
			sell_signal_week_m3##b2.profile_c ///
			sell_signal_week_m2##b2.profile_c ///
			sell_signal_week_m1##b2.profile_c ///
			sell_signal_week_p1##b2.profile_c ///
			sell_signal_week_p2##b2.profile_c ///
			sell_signal_week_p3##b2.profile_c ///
			sell_signal_week_p4##b2.profile_c ///
			sell_signal_week_p5##b2.profile_c ///
			sell_signal_week_p6##b2.profile_c ///
			sell_signal_week_p7##b2.profile_c ///
			sell_signal_week_p8##b2.profile_c ///
			if profile!="Not Advised" , ///
			absorb(numero_compte asset_id daily_date) cluster(numero_compte daily_date) noconstant


		*** PANEL A ****
		coefplot, omitted vertical ciopts(recast(rcap))  yline(0) xline(4.5, lwidth(1.5) lpattern(dash) lc(gs12)) graphregion(color(white))  xlabel(,labsize(vsmall)) ///
			ytitle("point estimate and 95% CI") xtitle("Weeks to/after Sell Recommendation") ///
			coeflabels(, wrap(10) interaction(" x ") ) ///
			keep( 1.sell_signal_week_m?  1.sell_signal_week_p? 1.sell_signal_week_p?plus)



		*** PANEL B ****
		coefplot, omitted vertical ciopts(recast(rcap))  yline(0) xline(4.5, lwidth(1.5) lpattern(dash) lc(gs12)) graphregion(color(white))  xlabel(,labsize(vsmall)) ///
			ytitle("point estimate and 95% CI") xtitle("Weeks to/after Sell Recommendation") ///
			coeflabels(, wrap(10) interaction(" x ") ) ///
			keep( 1.sell_signal_week_m*#*.profile_c  1.sell_signal_week_p*#*.profile_c) ///
			yscale(range(-0.5(0.5)1.0)) ytick(-0.5(0.5)1.0) ylabel(-0.5(0.5)1.0)






		*** FIGURE 4 ****

		reghdfe buy_dummy100 ///
			buy_signal_week_m4##b2.profile_c ///
			buy_signal_week_m3##b2.profile_c ///
			buy_signal_week_m2##b2.profile_c ///
			buy_signal_week_m1##b2.profile_c ///
			buy_signal_week_p1##b2.profile_c ///
			buy_signal_week_p2##b2.profile_c ///
			buy_signal_week_p3##b2.profile_c ///
			buy_signal_week_p4##b2.profile_c ///
			buy_signal_week_p5##b2.profile_c ///
			buy_signal_week_p6##b2.profile_c ///
			buy_signal_week_p7##b2.profile_c ///
			buy_signal_week_p8##b2.profile_c ///
			if profile!="Not Advised" , ///
			absorb(numero_compte asset_id daily_date) cluster(numero_compte daily_date) noconstant


		*** PANEL A ****

		coefplot, omitted vertical ciopts(recast(rcap))  yline(0) xline(4.5, lwidth(1.5) lpattern(dash) lc(gs12)) graphregion(color(white))  xlabel(,labsize(vsmall)) ///
			ytitle("point estimate and 95% CI") xtitle("Weeks to/after Buy Recommendation") ///
			coeflabels(, wrap(10) interaction(" x ") ) ///
			keep( 1.buy_signal_week_m?  1.buy_signal_week_p?  1.buy_signal_week_p?plus)




		*** PANEL B ****
		coefplot, omitted vertical ciopts(recast(rcap))  yline(0) xline(4.5, lwidth(1.5) lpattern(dash) lc(gs12)) graphregion(color(white))  xlabel(,labsize(vsmall)) ///
			ytitle("point estimate and 95% CI") xtitle("Weeks to/after Buy Recommendation") ///
			coeflabels(, wrap(10) interaction(" x ") ) ///
			keep( 1.buy_signal_week_m*#*.profile_c  1.buy_signal_week_p*#*.profile_c)




	}				


}		



********************************************************************************
* GENERATE POST VARIABLES
********************************************************************************

{


	* introduction of the plateform

	* including pilot phase
	scalar plateform_start_date = mdy(1,15,2018)
	scalar plateform_start_month = ym(2018,1)
	scalar plateform_start_quarter = yq(2018,1)
	scalar plateform_start_semester = yh(2018,1)
	scalar plateform_start_year = 2018

	* official launch date 
	scalar plateform_intro_date = mdy(5,31,2018)
	scalar plateform_intro_month = ym(2018,5)
	scalar plateform_intro_quarter = yq(2018,2)
	scalar plateform_intro_semester = yh(2018,1)
	scalar plateform_intro_year = 2018

	* pilot phase
	gen start_treatment_period = daily_date<=mdy(5,31,2018) & daily_date>=mdy(1,15,2018)
	gen start_treatment_period_month = monthly_date<=ym(2018,5) & monthly_date>=ym(2018,1)
	gen start_treatment_period_quarter = quarterly_date==yq(2018,1) | quarterly_date==yq(2018,2)
	gen start_treatment_period_semester = semester_date==yh(2018,1) 


	* post variables
	cap drop post_platform*
	gen post_platform = daily_date > plateform_start_date
	gen post_platform_month = monthly_date > plateform_start_month
	gen post_platform_quarter = quarterly_date > plateform_start_quarter
	gen post_platform_semester = semester_date > plateform_start_semester
	gen post_platform_year = year > plateform_intro_year

	* label variables 
	label variable post_platform_month "Post"
	label variable post_platform_quarter "Post"
	label variable post_platform_year "Post"

	label define post_lab 0 "" 1 "Post"
	label values post_platform post_lab
	label values post_platform_month post_lab
	label values post_platform_quarter post_lab
	label values post_platform_semester post_lab
	label values post_platform_year post_lab



	* pre/post in year
	forvalues i=0/3{
		gen post_year`i' = (post_platform==1) & (monthly_date>=plateform_start_month+(`i')*12) & (monthly_date<plateform_start_month+(`i'+1)*12)

	}


	forvalues i=1/3{
		gen pre_year`i' = (post_platform==0) & (monthly_date<plateform_start_month-(`i'-1)*12) & (monthly_date>=plateform_start_month-(`i')*12)

	}


	gen pre_year1_omit = 1
	label variable pre_year1_omit "-1"


	* pre/post in semesters 

	gen post_semester0 = (semester_date==plateform_start_semester)
	label variable post_semester0 "0"
	forvalues i=1/6{
		gen post_semester`i' = (post_platform==1) & (semester_date==plateform_start_semester+(`i'))
		label variable post_semester`i' "`i'"
	}

	forvalues i=1/6{
		gen pre_semester`i' = (post_platform==0) & (semester_date==plateform_start_semester-(`i'))
		label variable pre_semester`i' "-`i'"
	}

	gen pre_semester1_omit = 1
	label variable pre_semester1_omit "-1"


}



********************************************************************************
* GENERATE PGR/PLR
********************************************************************************

{

	* count sales
	sort numero_compte daily_date
	cap drop n_sell_day 
	by numero_compte daily_date: egen n_sell_day=sum(sell_dummy)


	* gains and losses
	by numero_compte daily_date: egen realized_gains = total(gain_dummy==1 & sell_dummy==1) if n_asset>=2 & n_sell_day>0
	by numero_compte daily_date: egen paper_gains = total(gain_dummy==1 & sell_dummy==0) if n_asset>=2 & n_sell_day>0
	gen PGR = realized_gains/(realized_gains+paper_gains)

	by numero_compte daily_date: egen realized_losses = total(gain_dummy==0 &  sell_dummy==1) if n_asset>=2 & n_sell_day>0
	by numero_compte daily_date: egen paper_losses = total(gain_dummy==0 & sell_dummy==0) if n_asset>=2 & n_sell_day>0
	gen PLR = realized_losses/(realized_losses+paper_losses)


	* investor month 
	bysort numero_compte monthly_date: egen realized_gains_month = total(realized_gains)
	bysort numero_compte monthly_date: egen paper_gains_month = total(paper_gains)
	bysort numero_compte monthly_date: egen realized_losses_month = total(realized_losses)
	bysort numero_compte monthly_date: egen paper_losses_month = total(paper_losses)

	* compute by profile and month 
	sort profile monthly_date
	by profile monthly_date: gen tag_profile_month = (_n==_N)

	by profile monthly_date: egen realized_gains_profmonth = sum(realized_gains/(tag_individual_day==1))
	by profile monthly_date: egen paper_gains_profmonth = sum(paper_gains/(tag_individual_day==1))
	gen PGR_profmonth = realized_gains_profmonth/(realized_gains_profmonth+paper_gains_profmonth)


	by profile monthly_date: egen realized_losses_profmonth = sum(realized_losses/(tag_individual_day==1))
	by profile monthly_date: egen paper_losses_profmonth = sum(paper_losses/(tag_individual_day==1))
	gen PLR_profmonth = realized_losses_profmonth/(realized_losses_profmonth+paper_losses_profmonth)


	gen ratio_PGR_PLR_profmonth = PGR_profmonth/PLR_profmonth
	gen diff_PGR_PLR_profmonth = PGR_profmonth - PLR_profmonth
	gen diff_PGR_PLR_profmonth100 = 100*(PGR_profmonth - PLR_profmonth)



	* future returns on asset 
	sort profile monthly_date

	* realized gains
	by profile monthly_date: egen next_1q_realized_gains_prfmonth = mean(next_1q_ret/(realized_gains==1))
	by profile monthly_date: egen next_1s_realized_gains_prfmonth = mean(next_1s_ret/(realized_gains==1))
	by profile monthly_date: egen next_1y_realized_gains_prfmonth = mean(next_1y_ret/(realized_gains==1))
	by profile monthly_date: egen next_2y_realized_gains_prfmonth = mean(next_2y_ret/(realized_gains==1))

	* paper gains
	by profile monthly_date: egen next_1q_paper_gains_prfmonth = mean(next_1q_ret/(paper_gains==1))
	by profile monthly_date: egen next_1s_paper_gains_prfmonth = mean(next_1s_ret/(paper_gains==1))
	by profile monthly_date: egen next_1y_paper_gains_prfmonth = mean(next_1y_ret/(paper_gains==1))
	by profile monthly_date: egen next_2y_paper_gains_prfmonth = mean(next_2y_ret/(paper_gains==1))

	* realized losses
	by profile monthly_date: egen next_1q_realized_losses_prfmonth = mean(next_1q_ret/(realized_losses==1))
	by profile monthly_date: egen next_1s_realized_losses_prfmonth = mean(next_1s_ret/(realized_losses==1))
	by profile monthly_date: egen next_1y_realized_losses_prfmonth = mean(next_1y_ret/(realized_losses==1))
	by profile monthly_date: egen next_2y_realized_losses_prfmonth = mean(next_2y_ret/(realized_losses==1))


	* paper losses
	by profile monthly_date: egen next_1q_paper_losses_prfmonth = mean(next_1q_ret/(paper_losses==1))
	by profile monthly_date: egen next_1s_paper_losses_prfmonth = mean(next_1s_ret/(paper_losses==1))
	by profile monthly_date: egen next_1y_paper_losses_prfmonth = mean(next_1y_ret/(paper_losses==1))
	by profile monthly_date: egen next_2y_paper_losses_prfmonth = mean(next_2y_ret/(paper_losses==1))


	* return differences 
	gen diff_next_1q_odean_prfmonth = next_1q_realized_gains_prfmonth - next_1q_paper_losses_prfmonth
	gen diff_next_1s_odean_prfmonth = next_1s_realized_gains_prfmonth - next_1s_paper_losses_prfmonth
	gen diff_next_1y_odean_prfmonth = next_1y_realized_gains_prfmonth - next_1y_paper_losses_prfmonth
	gen diff_next_2y_odean_prfmonth = next_2y_realized_gains_prfmonth - next_2y_paper_losses_prfmonth


}



********************************************************************************
* TABLE 3
********************************************************************************

{


	eststo clear
	estimates clear

	reghdfe ratio_PGR_PLR_profmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , noabsorb 

	estimates store odean_0

	reghdfe ratio_PGR_PLR_profmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , absorb(monthly_date) 

	estimates store odean_1

	reghdfe ratio_PGR_PLR_profmonth b2.profile_c##pre_year1 b2.profile_c##post_platform_month  if tag_profile_month==1 & profile!="Not Advised" , absorb(monthly_date) 

	estimates store odean_2

	* including not-advised 

	reghdfe ratio_PGR_PLR_profmonth b2.profile_c##post_platform_month if tag_profile_month==1 , noabsorb 

	estimates store odean_0all

	reghdfe ratio_PGR_PLR_profmonth b2.profile_c##post_platform_month if tag_profile_month==1, absorb(monthly_date) 

	estimates store odean_1all


	reghdfe ratio_PGR_PLR_profmonth b2.profile_c##pre_year1 b2.profile_c##post_platform_month  if tag_profile_month==1 , absorb(monthly_date) 

	estimates store odean_2all


}



********************************************************************************
* FIGURE 5
********************************************************************************

{
	* gen bootstrap confidence interval at the profile-month level 

	cap drop boot_se_PGR_PLR_profmonth
	gen boot_se_PGR_PLR_profmonth = .

	cap drop boot_p5*_PGR_PLR_profmonth
	gen boot_p5_PGR_PLR_profmonth = .
	gen boot_p5bc_PGR_PLR_profmonth = .
	gen boot_p5n_PGR_PLR_profmonth = .

	cap drop boot_p95*_PGR_PLR_profmonth
	gen boot_p95_PGR_PLR_profmonth = .
	gen boot_p95bc_PGR_PLR_profmonth = .
	gen boot_p95n_PGR_PLR_profmonth = .

	* define program
	cap program drop pgr_plr
	program define pgr_plr, rclass
		cap drop boot_*_profmonth
		egen boot_realized_gains_profmonth = sum(realized_gains_month)
		egen boot_paper_gains_profmonth = sum(paper_gains_month)
		gen boot_PGR_profmonth = boot_realized_gains_profmonth/(boot_realized_gains_profmonth+boot_paper_gains_profmonth)

		egen boot_realized_losses_profmonth = sum(realized_losses_month)
		egen boot_paper_losses_profmonth = sum(paper_losses_month)

		gen boot_PLR_profmonth = boot_realized_losses_profmonth/(boot_realized_losses_profmonth+boot_paper_losses_profmonth)

		gen boot_PGR_PLR_profmonth = boot_PGR_profmonth/boot_PLR_profmonth

		summarize boot_PGR_PLR_profmonth
		return scalar boot_PGR_PLR_profmonth = r(mean)
		disp "OK"
	end


	* bootstrap 
	foreach profile in "Highly Advised" "Lightly Advised" "Not Advised"{
		disp "`profile'"
		quiet levelsof monthly_date if profile=="`profile'", local(monthly_dates)

		foreach monthly_date of local monthly_dates{
			disp "`monthly_date'"
			preserve 
			keep if profile=="`profile'" & monthly_date==`monthly_date' & tag_individual_month==1

			bootstrap boot_PGR_PLR_profmonth=r(boot_PGR_PLR_profmonth), reps(10000) seed(123) level(95): pgr_plr
			local se_PGR_PLR_profmonth = e(se)[1,1]

			disp "bootstrap ok"
			restore

			replace boot_se_PGR_PLR_profmonth = `se_PGR_PLR_profmonth' if profile=="`profile'" & monthly_date==`monthly_date' 


		}
	}


	gen ub_boot_PGR_PLR_profmonth = ratio_PGR_PLR_profmonth + 1.96*boot_se_PGR_PLR_profmonth
	gen lb_boot_PGR_PLR_profmonth = ratio_PGR_PLR_profmonth - 1.96*boot_se_PGR_PLR_profmonth






	* graph 
	cap drop start_treatment_month_graph 
	gen start_treatment_month_graph = start_treatment_period_month
	replace start_treatment_month_graph = 3.4 if start_treatment_month_graph==1

	sort profile monthly_date
	graph twoway ///
		(connected ratio_PGR_PLR_profmonth monthly_date if tag_profile_month==1 & profile=="Highly Advised", msymbol(o) color(dkgreen) xline(`=plateform_start_month', lwidth(1) lpattern(dash) lc(gs12)) yline(1, lpattern(solid) lc(red%30)) ylabel(0.5(0.5)3)) ///
		(connected ratio_PGR_PLR_profmonth monthly_date if tag_profile_month==1 & profile=="Lightly Advised", msymbol(o) color(orange_red)) ///
		(rarea lb_boot_PGR_PLR_profmonth ub_boot_PGR_PLR_profmonth monthly_date if tag_profile_month==1 & profile=="Highly Advised", color(dkgreen%30) lpattern(none) lwidth(thin)  ) ///
		(rarea lb_boot_PGR_PLR_profmonth ub_boot_PGR_PLR_profmonth monthly_date if tag_profile_month==1 & profile=="Lightly Advised", color(orange_red%30) lpattern(none) lwidth(thin) ) ///
		, ytitle("PGR / PLR") xtitle("") legend(order(1 "Highly Advised" 2 "Lightly Advised")) 





}	

********************************************************************************
* TABLE 5 
********************************************************************************

{
	*** PANEL A 

	reghdfe diff_next_1q_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , noabsorb noconstant

	estimates store ret1q_0

	reghdfe diff_next_1q_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , absorb(monthly_date)  noconstant

	estimates store ret1q_1



	reghdfe diff_next_1s_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , noabsorb noconstant

	estimates store ret1s_0

	reghdfe diff_next_1s_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , absorb(monthly_date)  noconstant

	estimates store ret1s_1



	reghdfe diff_next_1y_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , noabsorb noconstant

	estimates store ret1y_0

	reghdfe diff_next_1y_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , absorb(monthly_date) noconstant

	estimates store ret1y_1

	reghdfe diff_next_2y_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , noabsorb noconstant

	estimates store ret2y_0

	reghdfe diff_next_2y_odean_prfmonth b2.profile_c##post_platform_month if tag_profile_month==1 & profile!="Not Advised" , absorb(monthly_date) noconstant

	estimates store ret2y_1




	*** PANEL B



	reghdfe ret_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte)

	estimates store ret_1

	reghdfe ret_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date ) cluster(numero_compte)

	estimates store ret_2

	reghdfe ret_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date#cohort_semester) cluster(numero_compte)

	estimates store ret_3

	reghdfe ret_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date monthly_date#cohort_semester) cluster(numero_compte)

	estimates store ret_4


	*** PANEL C

	reghdfe alphabh_4f_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte) noconstant

	estimates store alphabh_1

	reghdfe alphabh_4f_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date ) cluster(numero_compte) noconstant

	estimates store alphabh_2

	reghdfe alphabh_4f_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date#cohort_semester) cluster(numero_compte) noconstant

	estimates store alphabh_3

	reghdfe alphabh_4f_thismonth_perc b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date monthly_date#cohort_semester) cluster(numero_compte) noconstant

	estimates store alphabh_4



}



********************************************************************************
* TABLE 6 
********************************************************************************

{
	reghdfe port_weight_beta_mkt_rf b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte)

	estimates store beta_mkt

	reghdfe port_weight_beta_smb b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte)

	estimates store beta_smb


	reghdfe port_weight_beta_hml b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte)

	estimates store beta_hml


	reghdfe port_weight_beta_mom b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte)

	estimates store beta_mom


}	


********************************************************************************
* TABLE 7 
********************************************************************************

{

	eststo clear
	estimates clear


	* store lagged total asset
	sort numero_compte monthly_date tag_individual_month
	cap drop lag_total_asset*
	bysort numero_compte: gen lag_total_asset_tmp = total_asset[_n-1] if tag_individual_month==1
	bysort numero_compte monthly_date: egen lag_total_asset = mean(lag_total_asset_tmp)
	drop lag_total_asset_tmp

	* net flows 
	replace netflow_month = 0 if missing(netflow_month)
	gen perc_netflow_month = netflow_month/lag_total_asset

	* winsorize
	gen perc_netflow_month_win = perc_netflow_month 
	quiet sum perc_netflow_month if perc_netflow_month>0, det
	replace perc_netflow_month_win = r(p99) if perc_netflow_month_win>r(p99)
	quiet sum perc_netflow_month if perc_netflow_month<0, det
	replace perc_netflow_month_win = r(p1) if perc_netflow_month_win<r(p1)

	* in percentage
	replace perc_netflow_month_win = 100*perc_netflow_month_win


	* inflows 
	gen perc_inflow_month_win = perc_netflow_month_win if perc_netflow_month_win>0 & !missing(perc_netflow_month_win)
	replace perc_inflow_month_win = 0 if missing(perc_inflow_month_win) & !missing(perc_netflow_month_win)


	**** PANEL A 
	reghdfe perc_inflow_month_win b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte) noconstant

	estimates store inflow_1

	reghdfe perc_inflow_month_win b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date ) cluster(numero_compte) noconstant

	estimates store inflow_2

	reghdfe perc_inflow_month_win b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(monthly_date#cohort_semester numero_compte) cluster(numero_compte) noconstant

	estimates store inflow_3

	reghdfe perc_inflow_month_win b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(monthly_date#cohort_semester numero_compte advisor_id#monthly_date) cluster(numero_compte) noconstant

	estimates store inflow_4



	**** PANEL B
	gen perc_netflow_month_winab = perc_netflow_month
	replace perc_netflow_month_winab = perc_inflow_month_win if perc_netflow_month_winab>0


	reghdfe perc_netflow_month_winab b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte) noconstant

	estimates store netflow_1

	reghdfe perc_netflow_month_winab b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date ) cluster(numero_compte) noconstant

	estimates store netflow_2

	reghdfe perc_netflow_month_winab b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(monthly_date#cohort_semester numero_compte) cluster(numero_compte) noconstant

	estimates store netflow_3

	reghdfe perc_netflow_month_winab b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(monthly_date#cohort_semester numero_compte advisor_id#monthly_date) cluster(numero_compte) noconstant

	estimates store netflow_4




	**** PANEL C
	gen perc_netflow_month_wexit = perc_netflow_month_winab
	replace perc_netflow_month_wexit = -100 if exit_client_month==1


	reghdfe perc_netflow_month_wexit b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte monthly_date ) cluster(numero_compte) noconstant

	estimates store netflowexit_1

	reghdfe perc_netflow_month_wexit b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(numero_compte advisor_id#monthly_date ) cluster(numero_compte) noconstant

	estimates store netflowexit_2

	reghdfe perc_netflow_month_wexit b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(monthly_date#cohort_semester numero_compte) cluster(numero_compte) noconstant

	estimates store netflowexit_3

	reghdfe perc_netflow_month_wexit b2.profile_c##post_platform_month if tag_individual_month==1 & profile!="Not Advised", absorb(monthly_date#cohort_semester numero_compte advisor_id#monthly_date) cluster(numero_compte) noconstant

	estimates store netflowexit_4


}		




********************************************************************************
* GENERATE VARIABLES FOR COX MODEL ESTIMATIONS
********************************************************************************

{
	* Estimate investors' pre-treatment disposition effect and advice elasticity 


	cap drop coeff_buyreco_indiv_pre
	gen coeff_buyreco_indiv_pre = . //empty variable for coefficient

	cap drop coeff_gain_indiv_pre
	gen coeff_gain_indiv_pre = . //empty variable for coefficient


	// put the values of client IDs into a local macro called levels
	qui levelsof numero_compte if post_platform==0, local(levels)

	foreach co of local levels {

		// run the regression 
		cap qui reg buy_dummy buy_signal_committee if post_platform==0 & numero_compte== `co'

		// now replace coeff 
		cap replace coeff_buyreco_indiv_pre = _b[buy_signal_committee] if numero_compte== `co'


		// run the regression 
		cap qui reg sell_dummy gain_dummy if post_platform==0 & numero_compte== `co'

		// now replace coeff 
		cap replace coeff_gain_indiv_pre = _b[gain_dummy] if numero_compte== `co'

	}


	* split sample below/above median

	sum coeff_buyreco_indiv_pre if tag_individual==1, det
	local med_coeff = r(p50)
	cap drop high_follower_buy
	gen high_follower_buy = . 
	replace high_follower_buy = 1 if !missing(coeff_buyreco_indiv_pre) & coeff_buyreco_indiv_pre>=`med_coeff'
	replace high_follower_buy = 0 if !missing(coeff_buyreco_indiv_pre) & coeff_buyreco_indiv_pre<`med_coeff'

	label variable high_follower_buy "High Follower"

	cap label drop high_follower_buy_lab
	label define high_follower_buy_lab 0 "" 1 "High Follower"
	label values high_follower_buy high_follower_buy_lab


	sum coeff_gain_indiv_pre if tag_individual==1, det
	local med_coeff = r(p50)
	cap drop high_disposition
	gen high_disposition = . 
	replace high_disposition = 1 if !missing(coeff_gain_indiv_pre) & coeff_gain_indiv_pre>=`med_coeff'
	replace high_disposition = 0 if !missing(coeff_gain_indiv_pre) & coeff_gain_indiv_pre<`med_coeff'

	label variable high_disposition "High Disposition"

	cap label drop high_disp_lab
	label define high_disp_lab 0 "" 1 "High Disposition"
	label values high_disposition high_disp_lab




	* Define spells
	sort numero_compte asset_id daily_date
	by numero_compte asset_id: gen transaction_nb = 1 if _n==1
	by numero_compte asset_id: replace transaction_nb = transaction_nb[_n-1] + (quantite[_n-1]==0) if _n>1
	egen transaction_id = group(numero_compte asset_id transaction_nb)
	gen full_transaction_id = transaction_id

	* a position ends on the date the investor first sells part or all of her holdings 
	sort numero_compte asset_id transaction_id daily_date
	by numero_compte asset_id transaction_id: egen first_partial_sale_date = min(daily_date/(sell_dummy==1))
	replace transaction_id = . if !missing(first_partial_sale_date) & (daily_date>first_partial_sale_date)

	* gen time owned 
	sort numero_compte asset_id transaction_id daily_date
	by numero_compte asset_id transaction_id: gen time_owned = _n


	* Define control variables  
	global cox_control_var = "log_pam volatility_pos_t_1 volatility_neg_t_1 return_pos_t_1 return_neg_t_1 buy_signal_committee sell_signal_committee"


	* generate strata indicators (used in the table export to indicate strata)
	gen strata_advisor_indicator = 1
	gen strata_individual_indicator = 1
	gen strata_date_indicator = 1
	gen strata_asset_indicator = 1


	keep if !missing(transaction_id)

	stset time_owned, failure(sell_dummy) id(transaction_id)
}

********************************************************************************
* TABLE 4
********************************************************************************

{
	eststo clear
	estimates clear

	stcox gain_dummy##post_platform##b2.profile_c if profile!="Not Advised", vce(cluster  numero_compte ) nohr
	estimates store m0

	stcox gain_dummy##post_platform##b2.profile_c strata_date_indicator if profile!="Not Advised", strata(daily_date) vce(cluster  numero_compte ) nohr
	estimates store m1

	stcox gain_dummy##post_platform##b2.profile_c strata_asset_indicator if profile!="Not Advised", strata(asset_id) vce(cluster  numero_compte ) nohr
	estimates store m2

	stcox gain_dummy##post_platform##b2.profile_c strata_advisor_indicator if profile!="Not Advised", strata(advisor_id) vce(cluster  numero_compte ) nohr
	estimates store m3

	stcox gain_dummy##post_platform##b2.profile_c strata_individual_indicator if profile!="Not Advised", strata(numero_compte) vce(cluster  numero_compte ) nohr
	estimates store m4





	* Add controls 
	stcox gain_dummy##post_platform##b2.profile_c $cox_control_var if profile!="Not Advised", vce(cluster  numero_compte ) nohr
	estimates store m0_c

	stcox gain_dummy##post_platform##b2.profile_c $cox_control_var strata_date_indicator if profile!="Not Advised", strata(daily_date) vce(cluster  numero_compte ) nohr
	estimates store m1_c

	stcox gain_dummy##post_platform##b2.profile_c $cox_control_var strata_asset_indicator if profile!="Not Advised", strata(asset_id) vce(cluster  numero_compte ) nohr
	estimates store m2_c

	stcox gain_dummy##post_platform##b2.profile_c $cox_control_var strata_advisor_indicator if profile!="Not Advised", strata(advisor_id) vce(cluster  numero_compte ) nohr
	estimates store m3_c

	stcox gain_dummy##post_platform##b2.profile_c $cox_control_var strata_individual_indicator if profile!="Not Advised", strata(numero_compte) vce(cluster  numero_compte ) nohr
	estimates store m4_c




}



********************************************************************************
* FIGURE 6 
********************************************************************************

{

	*** PANEL A 


	cap drop omitted_year
	gen omitted_year = 1

	stcox gain_dummy ///
		i.year i.gain_dummy b2.profile_c /// 
		gain_dummy##i.year ///
		b2.profile_c##i.year  ///
		gain_dummy#b2.profile_c#2016.year  /// 
		omitted_year  /// 
		gain_dummy#b2.profile_c#2018.year ///
		gain_dummy#b2.profile_c#2019.year ///
		gain_dummy#b2.profile_c#2020.year ///
		gain_dummy#b2.profile_c#2021.year ///
		if profile!="Not Advised", vce(cluster  numero_compte ) nohr

	coefplot, omitted vertical ciopts(recast(rcap))  yline(0) xline(2.5, lwidth(1.5) lpattern(dash) lc(gs12)) graphregion(color(white))  xlabel(,labsize(small)) ///
		ytitle("point estimate and 95% CI") xtitle("") ///
		coeflabels(1.gain_dummy#1.profile_c#2016.year = " 2016 " omitted_year = " 2017 " 1.gain_dummy#1.profile_c#2018.year = " 2018 " 1.gain_dummy#1.profile_c#2019.year = " 2019 " 1.gain_dummy#1.profile_c#2020.year = " 2020 " 1.gain_dummy#1.profile_c#2021.year = " 2021 ", wrap(10) interaction(" x ") ) ///
		keep(1.gain_dummy#1.profile_c#*.year omitted_year) ///
		order(1.gain_dummy#1.profile_c#2016.year omitted_year 1.gain_dummy#1.profile_c#2018.year 1.gain_dummy#1.profile_c#2019.year 1.gain_dummy#1.profile_c#2020.year 1.gain_dummy#1.profile_c#2021.year) baselevels




	*** PANEL B

	cap drop omitted_semester
	gen omitted_semester = 1

	stcox gain_dummy ///
		i.semester_date i.gain_dummy b2.profile_c /// 
		gain_dummy##i.semester_date ///
		b2.profile_c##i.semester_date ///
		gain_dummy#b2.profile_c#112.semester_date gain_dummy#b2.profile_c#113.semester_date ///
		gain_dummy#b2.profile_c#114.semester_date ///
		omitted_semester ///
		gain_dummy#b2.profile_c#116.semester_date gain_dummy#b2.profile_c#117.semester_date ///
		gain_dummy#b2.profile_c#118.semester_date gain_dummy#b2.profile_c#119.semester_date ///
		gain_dummy#b2.profile_c#120.semester_date gain_dummy#b2.profile_c#121.semester_date ///
		gain_dummy#b2.profile_c#122.semester_date ///
		if profile!="Not Advised", vce(cluster  numero_compte ) nohr


	coefplot, omitted vertical ciopts(recast(rcap))  yline(0) xline(4.5, lwidth(1.5) lpattern(dash) lc(gs12)) graphregion(color(white))  xlabel(,labsize(vsmall)) ///
		ytitle("point estimate and 95% CI") xtitle("") ///
		coeflabels(1.gain_dummy#1.profile_c#112.semester_date = " 2016-H1 " 1.gain_dummy#1.profile_c#113.semester_date = " 2016-H2 " 1.gain_dummy#1.profile_c#114.semester_date = " 2017-H1 " omitted_semester = " 2017-H2" 1.gain_dummy#1.profile_c#116.semester_date = " 2018-H1 " 1.gain_dummy#1.profile_c#117.semester_date = " 2018-H2 " 1.gain_dummy#1.profile_c#118.semester_date = " 2019-H1 " 1.gain_dummy#1.profile_c#119.semester_date = " 2019-H2 " 1.gain_dummy#1.profile_c#120.semester_date = " 2020-H1 " 1.gain_dummy#1.profile_c#121.semester_date = " 2020-H2 " 1.gain_dummy#1.profile_c#122.semester_date = " 2021-H1 ", wrap(10) interaction(" x ")) ///
		keep(1.gain_dummy#1.profile_c#*.semester_date omitted_semester) ///
		order(1.gain_dummy#1.profile_c#112.semester_date 1.gain_dummy#1.profile_c#113.semester_date 1.gain_dummy#1.profile_c#114.semester_date omitted_semester 1.gain_dummy#1.profile_c#116.semester_date 1.gain_dummy#1.profile_c#117.semester_date 1.gain_dummy#1.profile_c#118.semester_date 1.gain_dummy#1.profile_c#119.semester_date 1.gain_dummy#1.profile_c#120.semester_date 1.gain_dummy#1.profile_c#121.semester_date) baselevels



}

********************************************************************************
* TABLE 8
********************************************************************************

{
	eststo clear
	estimates clear

	stcox gain_dummy##post_platform##b0.high_follower_buy if profile=="Highly Advised", vce(cluster  numero_compte ) nohr
	estimates store m0

	stcox gain_dummy##post_platform##b0.high_follower_buy strata_date_indicator if profile=="Highly Advised", strata(daily_date) vce(cluster  numero_compte ) nohr
	estimates store m1

	stcox gain_dummy##post_platform##b0.high_follower_buy strata_asset_indicator if profile=="Highly Advised", strata(asset_id) vce(cluster  numero_compte ) nohr
	estimates store m2

	stcox gain_dummy##post_platform##b0.high_follower_buy strata_advisor_indicator if profile=="Highly Advised", strata(advisor_id) vce(cluster  numero_compte ) nohr
	estimates store m3

	stcox gain_dummy##post_platform##b0.high_follower_buy strata_individual_indicator if profile=="Highly Advised", strata(numero_compte) vce(cluster  numero_compte ) nohr
	estimates store m4





	* Add controls 
	stcox gain_dummy##post_platform##b0.high_follower_buy $cox_control_var if profile=="Highly Advised", vce(cluster  numero_compte ) nohr iter(10)
	estimates store m0_c

	stcox gain_dummy##post_platform##b0.high_follower_buy $cox_control_var strata_date_indicator if profile=="Highly Advised", strata(daily_date) vce(cluster  numero_compte ) nohr iter(10)
	estimates store m1_c

	stcox gain_dummy##post_platform##b0.high_follower_buy $cox_control_var strata_asset_indicator if profile=="Highly Advised", strata(asset_id) vce(cluster  numero_compte ) nohr iter(10)
	estimates store m2_c

	stcox gain_dummy##post_platform##b0.high_follower_buy $cox_control_var strata_advisor_indicator if profile=="Highly Advised", strata(advisor_id) vce(cluster  numero_compte ) nohr iter(10)
	estimates store m3_c

	stcox gain_dummy##post_platform##b0.high_follower_buy $cox_control_var strata_individual_indicator if profile=="Highly Advised", strata(numero_compte) vce(cluster  numero_compte ) nohr iter(6)
	estimates store m4_c


}



********************************************************************************
* TABLE 9
********************************************************************************


{
	eststo clear
	estimates clear


	stcox gain_dummy##post_platform##b0.high_disposition if profile=="Highly Advised", vce(cluster  numero_compte ) nohr
	estimates store m0

	stcox gain_dummy##post_platform##b0.high_disposition strata_date_indicator if profile=="Highly Advised", strata(daily_date) vce(cluster  numero_compte ) nohr
	estimates store m1

	stcox gain_dummy##post_platform##b0.high_disposition strata_asset_indicator if profile=="Highly Advised", strata(asset_id) vce(cluster  numero_compte ) nohr
	estimates store m2

	stcox gain_dummy##post_platform##b0.high_disposition strata_advisor_indicator if profile=="Highly Advised", strata(advisor_id) vce(cluster  numero_compte ) nohr
	estimates store m3

	stcox gain_dummy##post_platform##b0.high_disposition strata_individual_indicator if profile=="Highly Advised", strata(numero_compte) vce(cluster  numero_compte ) nohr
	estimates store m4



	* Add controls 
	stcox gain_dummy##post_platform##b0.high_disposition $cox_control_var if profile=="Highly Advised", vce(cluster  numero_compte ) nohr iter(10)
	estimates store m0_c

	stcox gain_dummy##post_platform##b0.high_disposition $cox_control_var strata_date_indicator if profile=="Highly Advised", strata(daily_date) vce(cluster  numero_compte ) nohr iter(10)
	estimates store m1_c

	stcox gain_dummy##post_platform##b0.high_disposition $cox_control_var strata_asset_indicator if profile=="Highly Advised", strata(asset_id) vce(cluster  numero_compte ) nohr iter(10)
	estimates store m2_c

	stcox gain_dummy##post_platform##b0.high_disposition $cox_control_var strata_advisor_indicator if profile=="Highly Advised", strata(advisor_id) vce(cluster  numero_compte ) nohr iter(10)
	estimates store m3_c

	stcox gain_dummy##post_platform##b0.high_disposition $cox_control_var strata_individual_indicator if profile=="Highly Advised", strata(numero_compte) vce(cluster  numero_compte ) nohr iter(8)
	estimates store m4_c



}


